package com.dailyblue.java.thread;

import lombok.SneakyThrows;

import java.util.Vector;
import java.util.concurrent.FutureTask;

public class Main {

    private static void a() {
        // 产生了2个线程对象 新建状态
        DemoA a1 = new DemoA();
        DemoA a2 = new DemoA();
        // 启动线程  就绪状态
        a1.start();
        a2.start();
    }

    private static void b() {
        // 产生了2个任务
        DemoB b1 = new DemoB();
        DemoB b2 = new DemoB();
        // 产生了2个线程对象 分别执行2个任务
        Thread t1 = new Thread(b1);
        Thread t2 = new Thread(b2);
        t1.start();
        t2.start();
    }

    @SneakyThrows
    private static void c() {
        // 产生了2个任务
        DemoC c1 = new DemoC();
        DemoC c2 = new DemoC();
        // 转换
        FutureTask<String> task1 = new FutureTask<>(c1);
        FutureTask<String> task2 = new FutureTask<>(c2);
        // 产生了2个线程对象 分别执行2个任务
        Thread t1 = new Thread(task1);
        Thread t2 = new Thread(task2);
        t1.start();
        t2.start();
        // 获取返回结果
        String result1 = task1.get();
        String result2 = task2.get();
        System.out.println(result1);
        System.out.println(result2);
    }

    private static void d() {
        DemoD1 d1 = new DemoD1();
        DemoD dd1 = new DemoD(d1);
        DemoD dd2 = new DemoD(d1);
        DemoD dd3 = new DemoD(d1);
        dd1.start();
        dd2.start();
        dd3.start();
    }
    private static void e() {
        DemoE1 d1 = new DemoE1();
        DemoE dd1 = new DemoE(d1);
        DemoE dd2 = new DemoE(d1);
        DemoE dd3 = new DemoE(d1);
        dd1.start();
        dd2.start();
        dd3.start();
    }
    private static void f() {
        DemoF1 d1 = new DemoF1();
        DemoF dd1 = new DemoF(d1);
        DemoF dd2 = new DemoF(d1);
        DemoF dd3 = new DemoF(d1);
        dd1.start();
        dd2.start();
        dd3.start();
    }
    public static void main(String[] args) {
        f();
    }
}
/*
火车票售票问题，火车票有1000张，分3个窗口售出。
 */